from lxml import etree

text='''
<li class="li li-first"><a href="link.html">first item</a></li>
'''

html=etree.HTML(text)
#contains包含class属性中，有Li名称
res=html.xpath('//li[contains(@class, "li")]/a/text()')
# print(res)
#['first item']

text2='''
<li class="li li-first" name="item"><a href="link.html">first item</a></li>
'''
html=etree.HTML(text2)
res=html.xpath('//li[contains(@class,"li") and @name="item"]/a/text()')
print(res)
['first item']

res=html.xpath('//li[contains(@class,"li") and @name="item"]/a/@href')
print(res)
#['link.html']
